from django import forms
from django.core.exceptions import ValidationError
from .models import Doctor


# from django.contrib.auth import get_user_model
# User = get_user_model()

class DoctorRegisterForm(forms.Form):
    doctor_account = forms.CharField(max_length=50, min_length=6,
                                     error_messages={
                                         'required': '请输入账号',
                                         "max_length": '账号位数最高为50位',
                                         "min_length": '账号位数最低为6位',

                                     })
    doctor_password = forms.CharField(max_length=60, min_length=6,
                                      error_messages={
                                          'required': '密码不能为空',
                                          "max_length": '密码位数过多',
                                          "min_length": '密码位数至少为6位',

                                      })

    def clean_doctor_account(self):
        doctor_account = self.cleaned_data.get('doctor_account')
        print("验证手机号是否已经存在")
        print(Doctor.objects.filter(doctor_account=doctor_account).exists())
        if Doctor.objects.filter(doctor_account=doctor_account).exists():
            raise ValidationError('该账号已被注册，请使用其他账号名')
        return doctor_account
